﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace LinWon.Core.Data
{
    /// <summary>
    /// 数据库操作工厂类
    /// </summary>
    public abstract class DataFactory
    {
        private static Dictionary<string, SqlHelper> _helperPool = new Dictionary<string, SqlHelper>();

        /// <summary>
        /// 获取数据库操作类
        /// </summary>
        /// <param name="ConnSection">连接配置节名称</param>
        /// <returns></returns>
        public static SqlHelper GetHelper(string ConnSection)
        {
            if (_helperPool.ContainsKey(ConnSection)) return _helperPool[ConnSection];
            else
            {
                string connStr = ConfigurationManager.ConnectionStrings[ConnSection].ConnectionString;
                SqlHelper help = new SqlHelper(connStr);
                _helperPool.Add(ConnSection, help);
                return help;
            }
        }

        /// <summary>
        /// 获取数据库操作类(默认连接字符串ConnStr)
        /// </summary>        
        /// <returns></returns>
        public static SqlHelper GetHelper()
        {
            string ConnSection = "ConnStr";
            return GetHelper(ConnSection);
        }
    }
}
